package com.huang.core.helper

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.provider.Settings


object IntentHelper {
    const val ACTIVITY_SYSTEM_LCOATION_MANAGER = 11004

    /** 跳转至系统定位服务页 */
    fun openLocationManagerWindow(activity: Activity) {
        val intent = Intent()
        intent.action = Settings.ACTION_LOCATION_SOURCE_SETTINGS
        activity.startActivityForResult(intent, ACTIVITY_SYSTEM_LCOATION_MANAGER)
    }

    /** Android6.0及以上系统，在doze模式下添加进白名单，进行保活 */
    fun requestIgnoreBatteryOptimizations(activity: Activity) {
        val packageName = activity.packageName
        val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
        intent.data = Uri.parse("package:$packageName")
        try {
            activity.startActivity(intent)
        } catch (ex: Exception) {
            ex.printStackTrace()
        }
    }

}
